﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GameAnimationManager
{

    private Animator animator;
    private ActiveObject obj;

    private float aniTime;
    private float aniSpeed;

    public GameAnimationManager(ActiveObject obj)
    {
        this.obj = obj;
    }

    public ActiveObject getOwner()
    {
        return obj;
    }

    public void setAnimator(Animator ani)
    {
        animator = ani;
    }

    public Animator getAnimator()
    {
        return animator;
    }



    public AnimationClip getAnimation(int index)
    {
        AnimationClip[] aLst = animator.runtimeAnimatorController.animationClips;
        return aLst[index];
    }
    public float getLength()
    {
        AnimationClip[] aLst = animator.runtimeAnimatorController.animationClips;
        return aLst.Length;
    }

    public float getAniSpeed()
    {
        return animator.speed;
    }

    public float getAniTime()
    {
        return aniTime;
    }
    public int getCurrentFrameIndex()
    {

        //当前动画机播放时长
        float currentTime = animator.GetCurrentAnimatorStateInfo(0).normalizedTime;
        //动画片段长度
        float length = animator.GetCurrentAnimatorClipInfo(0)[0].clip.length;
        //获取动画片段帧频
        float frameRate = animator.GetCurrentAnimatorClipInfo(0)[0].clip.frameRate;
        float totalFrame = length / (1 / frameRate);
        int currentFrame = (int)((totalFrame * currentTime) % totalFrame);

        return currentFrame;

    }

    public void setAni(string aniFlag)
    {
        animator.ResetTrigger(aniFlag);
        animator.SetTrigger(aniFlag);

        aniTime = 0.0f;
        aniSpeed = 1.0f;
    }

    public void setAni(string aniString, int num)
    {
        animator.SetInteger(aniString, num);
        aniTime = 0.0f;
        aniSpeed = 1.0f;
    }

    public void setAniSpeed(float speed)
    {
        animator.speed = speed;
        aniSpeed = speed;

    }
    public void Rewind()
    {
        ;
    }

    public bool isPlay(string str)
    {
        return false;
    }




    public void onProc()
    {
        aniTime = aniTime + Time.deltaTime * aniSpeed;
    }

}